using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace Main.AStar
{
    public class GridNodes
    {
        public int width;
        public int height;
        public Node[,] gridNodes;

        /// <summary>
        /// 构造函数,初始化网格节点数组
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public GridNodes(int width, int height)
        {
            this.width = width;
            this.height = height;

            gridNodes = new Node[width, height];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    gridNodes[x, y] = new Node(new Vector2Int(x, y));
                }
            }
        }

        public bool TryGetGridNode(int xPos, int yPos, out Node node)
        {
            if (xPos >= 0 && xPos < width && yPos >= 0 && yPos < height)
            {
                node = gridNodes[xPos, yPos];
                return true;
            }

            node = null;
            return false;
        }

    }
}